#include "capture.h"
#include "tim.h"



Capture_TypeDef Heart;

void Capture_Start(Capture_TypeDef *cap)
{
  if (cap->State == 0)
  {
    cap->State++;
    cap->Cnt_Start = TIM2->CNT;//HAL_TIM_ReadCapturedValue(&htim2, TIM_CHANNEL_1);
    cap->timcnt = 0;
  }
}

void Capture_End(Capture_TypeDef *cap)
{
  if (cap->State == 1)
  {
    cap->Cnt_Period = cap->timcnt;
    cap->State = 0;
    cap->Cnt_End = TIM2->CNT;//HAL_TIM_ReadCapturedValue(&htim2, TIM_CHANNEL_1);
    cap->Complete = 1;

  }
}
uint32_t Capture_GetValue(Capture_TypeDef *cap)
{
  return cap->Cnt_Period * 1000 + cap->Cnt_End - cap->Cnt_Start;
}





